import {Module} from '@nestjs/common';
import {UserModule} from './modules/user/user.module';
import {ConfigModule, ConfigService} from "@nestjs/config";
import * as process from "process";
import * as dotenv from "dotenv";
import {TypeOrmModule, TypeOrmModuleOptions} from "@nestjs/typeorm";
import {UserEntity} from "./modules/user/user.entity";
import configuration from "./config/configuration";
// import { RedisModule } from '@nestjs-modules/ioredis';
// import { ScheduleModule } from '@nestjs/schedule';
// import { ThrottlerModule } from '@nestjs/throttler';
// import { AuthModule } from './modules/auth/auth.module';
// import { VehicleModule } from './modules/vehicle/vehicle.module';
// import { AppointmentModule } from './modules/appointment/appointment.module';
// import { MaintenanceModule } from './modules/maintenance/maintenance.module';
// import { NotificationModule } from './modules/notification/notification.module';
// 最先加载环境变量（建议在应用入口文件顶部）
require('dotenv').config();

const envFilePath = `.env.${process.env.NODE_ENV || `development`}`

@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true,
            envFilePath,
            load: [configuration]
        }),

        TypeOrmModule.forRootAsync({
            inject: [ConfigService],
            useFactory: (config: ConfigService) => ({
                ...config.get('app.database'),
                autoLoadEntities: true,
            })
        } as TypeOrmModuleOptions),

        // RedisModule.forRootAsync({
        //     inject: [ConfigService],
        //     useFactory: (config: ConfigService) => ({
        //         config: config.get('app.redis'),
        //     })
        // }),

        // ThrottlerModule.forRoot({
        //     ttl: 60,
        //     limit: 100,
        // }),

        // ScheduleModule.forRoot(),

        UserModule,
        // AuthModule,
        // VehicleModule,
        // AppointmentModule,
        // MaintenanceModule,
        // NotificationModule,
    ],
    controllers: [],
    providers: [],
})
export class AppModule {
}
